package com.amumu.drama.common.constant;

import com.google.common.collect.Maps;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;

@Getter
public enum SourceTypeEnum {
    /* 订单来源：0->未知；1-PC订单；2->app订单 */
    UNKNOWN(0, "UNKNOWN", "未知"),
    PC(1, "PC", "PC电脑"),
    APP(2, "APP", "APP收集"),
    ;

    /** 索引 */
    private static final Map<Integer, SourceTypeEnum> KEY_UNINDEX = Maps.uniqueIndex(Arrays.asList(values()), SourceTypeEnum::getCode);
    /** 索引 */
    private static final Map<String, SourceTypeEnum> URL_UNINDEX = Maps.uniqueIndex(Arrays.asList(values()), SourceTypeEnum::getType);
    /** key */
    private Integer code;
    /** code url */
    private String type;
    /** 描述 */
    private String desc;

    SourceTypeEnum(int code, String type, String desc) {
        this.code = code;
        this.type = type;
        this.desc = desc;
    }

    public static SourceTypeEnum getByCode(Integer code) {
        return KEY_UNINDEX.get(code);
    }

    public static SourceTypeEnum getByType(String type) {
        return URL_UNINDEX.getOrDefault(type, null);
    }
}
